package vn.com.aptech.msh.business;

import java.io.UnsupportedEncodingException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.Stateless;
import javax.mail.MessagingException;
import javax.mail.internet.AddressException;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import vn.com.aptech.msh.entities.Enquiry;
import vn.com.aptech.msh.utils.MailHelper;

/**
 *
 * @author trietto
 */
@Stateless
public class EnquiryBean implements IEnquiryBean {

    private final String SITE_EMAIL = "ngonhatphuong88@gmail.com";
    @PersistenceContext(unitName = "MySweetHome-ejbPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public EnquiryBean() {
    }

    @Override
    public void sendEnquiry(Enquiry enquiry) {
        getEntityManager().persist(enquiry);
        MailHelper.sendMail(enquiry.getSenderEmail(), SITE_EMAIL, enquiry.getSenderName(), enquiry.getSubject(), enquiry.getContent());
    }
}
